home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / allswag.zip / JOYSTICK.SWG < prev    next >
Text File  |  1993-07-01  |  30KB  |  1 lines

  1. SWAGOLX.EXE (c) 1993 GDSOFT  ALL RIGHTS RESERVED 00006         JOYSTICK ROUTINES                                                 1      05-28-9313:49ALL                      SWAG SUPPORT TEAM        JOYSTCK1.PAS             IMPORT              22          Unit Joystick;πInterfaceπ Uses Crt;ππ { Joystick Interface For Turbo Pascal V. 4.0 and aboveπ   Public Domain, November 1989 byπ   JonSoft Technologies Inc.π   (C) 1989 JonSoft Technologies Inc. }ππConstπ centX : Byte=80;π centY : Byte=40;π Joyst : Boolean=True;ππProcedure FastInitJS;πProcedure BetterInitJS( range : Byte );πFunction joy_X : Byte;πFunction joy_Y : Byte;πFunction button_1 : Byte;πFunction button_2 : Byte;πFunction Horiz : shortint;πFunction Vert : shortint;πππImplementationππConstπ rangexm : Byte=25;π rangeym : Byte=20;π rangexp : Byte=25;π rangeyp : Byte=25;ππFunction joy_X : Byte;π  Varπ    x : Word;π  beginπ    x := 0;π    Port[$201] := $ff;π    While Port[$201] and $1=1 do Inc(x);π    joy_X := x;π  end;ππFunction joy_Y : Byte;π  Varπ    y : Word;π  beginπ    y := 0;π    Port[$201] := $0;π    While Port[$201] and $2=2 do Inc(y);π    joy_Y := y;π  end;ππProcedure FastInitJs;π  beginπ    centX := joy_X;π    centY := joy_Y;π  end;ππFunction button_1 : Byte;π  beginπ    button_1 := ((Port[$201] and $10) Xor $10) ShR 4;π  end;ππFunction button_2 : Byte;π  beginπ    button_2 := ((Port[$201] and $20) Xor $20) ShR 5;π  end;ππProcedure BetterInitJs(range : Byte);π  Varπ(*    Ch : Char; *)π    uprjoyX, uprjoyY, centrjoyX, centrjoyY, lowrjoyX, lowrjoyY : Byte;ππbeginπ WriteLN('Are you using a joystick? (Button = yes, RETURN = no)');π Repeatπ  if button_1+button_2 > 0 then Joyst := True;π  if KeyPressed then Joyst := False;π Until (button_1+button_2 > 0) or KeyPressed;π if Joyst = True then beginπ  Repeat Until button_1+button_2 = 0;π  WriteLN('Move joystick to UPPER RIGHT corner and press a button.');π  Repeat Until button_1+button_2 > 0;π  uprjoyX := joy_X;π  uprjoyY := joy_Y;π  Repeat Until button_1+button_2 = 0;π  WriteLN('Move joystick to CENTER and press a button.');π  Repeat Until button_1+button_2 > 0;π  centrjoyX := joy_X;π  centrjoyY := joy_Y;π  centX := centrjoyX;π  centY := centrjoyY;π  Repeat Until button_1+button_2 = 0;π  WriteLN('Move joystick to LOWER LEFT CorNER and press a button.');π  Repeat Until button_1+button_2 > 0;π  lowrjoyX := joy_X;π  lowrjoyY := joy_Y;π  rangexm := (centrjoyX-uprjoyX) div range;π  rangexp := (lowrjoyX-centrjoyX) div range;π  rangeym := (centrjoyY-uprjoyY) div range;π  rangeyp := (lowrjoyY-centrjoyY) div range;π end;πend;ππFunction Horiz : shortint;π  beginπ    if joy_X<centX-rangexm then Horiz := -1π    else if joy_X > centX+rangexp then Horiz := 1π    else Horiz := 0;π  end;ππFunction Vert : shortint;π  beginπ    if joy_Y<centY-rangeym then Vert := -1π    else if joy_Y > centY+rangeyp then Vert := 1π    else Vert := 0;π  end;ππend.π                                                          2      05-28-9313:49ALL                      SWAG SUPPORT TEAM        JOYSTCK2.PAS             IMPORT              30          {πAnyone know how to read the Joystick.... I only need Joy(1) read....πI have used 1 Procedure i d/led, but all it did was tell me if the buttonsπwere down (it didnt work in telling me which direction (it should of))π}πProgram JOYSTICK;ππUses Crt, Dos;ππ(*πWRITTEN BY JAMES P. MCADAMS - 25 DECEMBER 1984ππProgram DEMONSTRATinG THE USE of TURBO PASCAL to ACCESS THEπIBM-PC GAME CONTROL ADAPTER. THE TWO Function CALLS ARE EACHπCompLETE in ITSELF. EITHER ONE or BOTH CAN BE MOVED to ANYπProgram THAT NEEDS THE USE of JOYSTICKS or PADDLES.π*)ππππVarπI: Integer;πTEMP: Byte;πππ   Function BUTtoN_PRESSED (WHICH_ONE: Char): Boolean;π   (* RETURN True if THE BUTtoN IS PRESSED *)π   Constπ      JOYPorT = $201; (* LOCATION of THE GAME PorT *)π   Varπ      MASK: Byte;π   beginπ   if not (WHICH_ONE in ['A'..'D']) then WHICH_ONE := 'A';π   Case WHICH_ONE ofπ      'A': MASK := 16;π      'B': MASK := 32;π      'C': MASK := 64;π      'D': MASK := 128;π      end;π   BUTtoN_PRESSED := (PorT [JOYPorT] and MASK) = 0;π   end; (* BUTtoN_PRESSED *)πππ   Function JOYSTICK_POS (WHICH_ONE: Char): Integer;π   (*π   With A KRAFT JOYSTICK, VALUES RETURNED ARE in THE RANGE 4 to ABOUTπ   140. if YOUR MACHinE RUNS FASTER THAN A STandARD IBM-PC or if YOUπ   MODifY YOUR GAME ADAPTER CARD With BIGGER CAPACItoRS, YOU WILLπ   GET LARGER COUNTS and YOU MUST MODifY "MAXCOUNT".ππ   CALLinG A JOYSTICK THAT IS not in USE or ONE THAT HAS GONEπ   OVER-RANGE (COUNT REACHED MAXCOUNT) YIELDS A VALUE of 0.π   *)π   Constπ      MAXCOUNT =  2000; (* MODifY THIS if YOU CAN GET LONGER COUNTS     *)π      JOYPorT  = $201; (* For inForMATION ONLY: LOC of GAME inPUT PorT *)π   Varπ      COUNTER: Integer;π      MASK: Byte;π   beginπ   if not (WHICH_ONE in ['A'..'D']) then WHICH_ONE := 'A';π   Case WHICH_ONE ofπ      'A': MASK := 1;π      'B': MASK := 2;π      'C': MASK := 4;π      'D': MASK := 8;π      end;π   (*π   THIS ASSEMBLY CODE CAUses THE CX REGISTER to COUNT doWN FROM "MAXCOUNT"π   toWARD ZERO. WHEN CX REACHES ZERO or WHEN THE ONE-SHOT ON THE GAMEπ   ADAPTER TIMES OUT, THE LOOPinG StoPS and "COUNTER" IS ASSIGNED THE NUMBERπ   of COUNTS THAT toOK PLACE. MAXCOUNT SHOULD BE CHOSEN SO THAT CX NEVERπ   REACHES 0 SO THAT THE USABLE RANGE of THE JOYSTICK WILL not BE LIMITED.π   *)π   Inline (π      $B9/MAXCOUNT/       (*       MOV CX,MAXCOUNT inITIALIZE doWN-COUNTER *)π      $BA/JOYPorT/        (*       MOV DX,JOYPorT  PorT ADDR of JOYSTICKS  *)π      $8A/$A6/MASK/       (*       MOV AH,MASK[BP] MASK For DESIRED 1-SHOT *)π      $EE/                (*       OUT DX,AL       START THE ONE-SHOTS     *)π      $EC/                (* READ: in  AL,DX       READ THE ONESHOTS       *)π      $84/$C4/            (*      TEST AL,AH       CHECK DESIRED ONE-SHOT  *)π      $E0/$FB/            (*    LOOPNZ READ        Repeat Until TIMED OUT  *)π      $89/$8E/COUNTER);   (*       MOV COUNTER[BP],CX  THIS MAKES CX AVAIL-*)π                          (*                           ABLE to TURBO       *)π   if COUNTER = 0π      then JOYSTICK_POS := 0 (* OVER-RANGE or not in USE *)π      else JOYSTICK_POS := MAXCOUNT - COUNTER;π   end; (* JOYSTICK_POS *)πππbegin    (***** DEMO Program - MAin CODE *****)πClrScr;πGotoXY (1, 2);πWriteLN ('JOYSTICKS':10, 'BUTtoNS':10);πWrite   ('A':5, 'B':5, 'A':5, 'B':5);ππWhile True do (* PRESS CTRL C to StoP THE Program *)π   beginπ   GotoXY (1, 5);π   Write (JOYSTICK_POS ('A'):5, JOYSTICK_POS ('B'):5);π   if BUTtoN_PRESSED ('A')π      then Write ('PRES':5)π      else Write ('UP':5);π   if BUTtoN_PRESSED ('B')π      then Write ('PRES':5)π      else Write ('UP':5);π   end;πend.π                                                                                                                         3      05-28-9313:49ALL                      SWAG SUPPORT TEAM        JOYSTCK3.PAS             IMPORT              42          {πto whomever sent me a message concerning joystick support, I apologize that Iπcannot send this message to you directly (message Pointers were screwed up on mπend, and I lost your message), but here is both my source For a Unit and aπsample Program.  First I'd like to say that my Unit may be somewhat inComplete.πhave only a Single joystick port, so reading of two ports is impossible.  Forπthis reason, I'd like to ask any and all to make suggestions, and modificationsπso that I, and all Programmers, may have a Complete Unit.  Also, remarks haveπnot been added to the Program, if an explanation is needed, please feel free toπask...I'd be more than happy to give explanations For my work.  Anyhows, here iπis...π}πUnit Joystick;ππInterfaceππFunction JoystickExists : Boolean;πFunction JoystickPosX : Integer;πFunction JoystickPosY : Integer;πFunction JoystickButtonA : Boolean;πFunction JoystickButtonB : Boolean;ππImplementationππUses Crt, Dos;ππConst GamePortAddr = $200;π     MaxCount = 500;ππFunction JoystickStatus (Mask : Byte) : Integer;πVar Counter : Integer;πLabel Read;πbeginπ  Asmπ  mov cx,MaxCountπ  mov dx,GamePortAddrπ  mov ah,Maskπ  out dx,alπ  read:π     in al,dxπ     test al,ahπ     loopnz readπ  mov counter,cxπ  end;π  JoystickStatus := MaxCount - Counter;π  Delay (2);πend;ππFunction JoystickPosX : Integer;πbeginπ  JoystickPosX := JoystickStatus (1);πend;ππFunction JoystickPosY : Integer;πbeginπ  JoystickPosY := JoystickStatus (2);πend;ππFunction JoystickButtonA : Boolean;πbeginπ  JoystickButtonA := (Port [GamePortAddr] and 16) = 0;πend;ππFunction JoystickButtonB : Boolean;πbeginπ  JoystickButtonB := (Port [GamePortAddr] and 32) = 0;πend;ππFunction JoystickExists : Boolean;πVar Regs : Registers;πbeginπ  JoystickExists := not ((JoystickPosX = 0) and (JoystickPosY = 0));πend;ππend.πππProgram JoyTest;ππUses Crt, Dos, AniVGA, Joystick;ππVar XMin, XMax, YMin, YMax,π   XRange, YRange,π   X, Y,π   PosX, PosY,π   Bullet1X, Bullet1Y,π   Bullet2X, Bullet2Y : Integer;π   Shooting1, Shooting2 : Boolean;π   ShootNext : Boolean;ππProcedure CalibrateJoystick (Var XMin, XMax, YMin, YMax : Integer);πbeginπ  Write ('Press joystick to upper left corner and press button one...');π  Repeat Until JoystickButtonA;π  XMin := JoystickPosX;π  YMin := JoystickPosY;π  Writeln ('OK.');π  Repeat Until not JoystickButtonA;π  Write ('Press joystick to lower right corner and press button two...');π  Repeat Until JoystickButtonB;π  XMax := JoystickPosX;π  YMax := JoystickPosY;π  Writeln ('OK.');π  Repeat Until not JoystickButtonB;πend;ππProcedure AnimateShip;πbeginπ  X := JoystickPosX - XMin;π  if (X <= XRange div 3) thenπ     Dec (PosX, 3)π  else if (X > XRange * 2 div 3) thenπ     Inc (PosX, 3);π  Y := JoystickPosY - YMin;π  if (Y <= YRange div 3) thenπ     Dec (PosY, 3)π  else if (Y > YRange * 2 div 3) thenπ     Inc (PosY, 3);π  SpriteX [0] := PosX;π  SpriteY [0] := PosY;πend;ππProcedure AnimateBullets;πbeginπ  if Shooting1 thenπ     if (Bullet1Y < 0) thenπ        Shooting1 := Falseπ     elseπ        Dec (Bullet1Y, 8)π  elseπ     beginπ        Bullet1X := PosX + 3;π        Bullet1Y := PosY + 14;π     end;π  if Shooting2 thenπ     if (Bullet2Y < 0) thenπ        Shooting2 := Falseπ    elseπ        Dec (Bullet2Y, 8)π  elseπ     beginπ        Bullet2X := PosX + 30;π        Bullet2Y := PosY + 14;π     end;π  SpriteX [1] := Bullet1X;π  SpriteY [1] := Bullet1Y;π  SpriteX [2] := Bullet2X;π  SpriteY [2] := Bullet2Y;πend;ππbeginπ  if JoystickExists and (LoadSprite ('SHIP1.COD', 1) = 1) andπ     (LoadSprite ('BULLET.COD', 2) = 1) thenπ     beginπ        ClrScr;π        CalibrateJoystick (XMin, XMax, YMin, YMax);π        ClrScr;π        InitGraph;π        SpriteN [0] := 1;π        SpriteN [1] := 2;π        SpriteN [2] := 2;π        PosX := 160;π        PosY := 160;π        Shooting1 := False;π        XRange := XMax - XMin;π        YRange := YMax - YMin;π        ShootNext := Boolean (0);π        While not (JoystickButtonA and JoystickButtonB) doπ           beginπ              if JoystickButtonA and not JoystickButtonB thenπ                 if not Shooting1 and ShootNext thenπ                    beginπ                       Bullet1X := PosX + 3;π                       Bullet1Y := PosY + 14;π                       Shooting1 := True;π                       ShootNext := False;π                    endπ                 else if not Shooting2 and not ShootNext thenπ                    beginπ                       Bullet2X := PosX + 30;π                       Bullet2Y := PosY + 14;π                       Shooting2 := True;π                       ShootNext := True;π                    end;π              While JoystickButtonA doπ                 beginπ                    AnimateShip;π                    AnimateBullets;π                    Animate;π                 end;π              AnimateShip;π              AnimateBullets;π              Animate;π           end;π        CloseRoutines;π     endπ  elseπ     Writeln ('Game card not installed.');πend.π{πI apologize For giving you an example that Uses another Unit.  if need be, thisπProgram can be easily modified to provide a successful example.  Hope thisπhelps, and I hope my Programming is not toO bad.π}                                                4      05-28-9313:49ALL                      SWAG SUPPORT TEAM        JOYSTCK4.PAS             IMPORT              5           πAnyone know how to read the Joystick....ππif you are using an AT (286 or later), here's the easy way.πUse Intr ($15, Regs), and load AH With the $84, then loadπDX With 1 to get the joystick status' and 0 to get theπbutton status.  if you use DX=1, it returns:ππAX x of joystick AπBX y of joystick AπCX x of joystick BπDX y of joystick Bππif you use DX=0:ππAL button status, bit #π   4 joystick A,button 1π   5 joystick A,button 2π   6 joystick B,button 1π   7 joystick B,button 2π                               5      05-28-9313:49ALL                      SWAG SUPPORT TEAM        JOYSTCK5.PAS             IMPORT              42          {πto whomever sent me a message concerning joystick support, I apologize that Iπcannot send this message to you directly (message Pointers were screwed up on mπend, and I lost your message), but here is both my source For a Unit and aπsample Program.  First I'd like to say that my Unit may be somewhat inComplete.πhave only a Single joystick port, so reading of two ports is impossible.  Forπthis reason, I'd like to ask any and all to make suggestions, and modificationsπso that I, and all Programmers, may have a Complete Unit.  Also, remarks haveπnot been added to the Program, if an explanation is needed, please feel free toπask...I'd be more than happy to give explanations For my work.  Anyhows, here iπis...π}ππUnit Joystick;ππInterfaceππFunction JoystickExists : Boolean;πFunction JoystickPosX : Integer;πFunction JoystickPosY : Integer;πFunction JoystickButtonA : Boolean;πFunction JoystickButtonB : Boolean;ππImplementationππUses Crt, Dos;ππConst GamePortAddr = $200;π     MaxCount = 500;ππFunction JoystickStatus (Mask : Byte) : Integer;πVar Counter : Integer;πLabel Read;πbeginπ  Asmπ  mov cx,MaxCountπ  mov dx,GamePortAddrπ  mov ah,Maskπ  out dx,alπ  read:π     in al,dxπ     test al,ahπ     loopnz readπ  mov counter,cxπ  end;π  JoystickStatus := MaxCount - Counter;π  Delay (2);πend;ππFunction JoystickPosX : Integer;πbeginπ  JoystickPosX := JoystickStatus (1);πend;ππFunction JoystickPosY : Integer;πbeginπ  JoystickPosY := JoystickStatus (2);πend;ππFunction JoystickButtonA : Boolean;πbeginπ  JoystickButtonA := (Port [GamePortAddr] and 16) = 0;πend;ππFunction JoystickButtonB : Boolean;πbeginπ  JoystickButtonB := (Port [GamePortAddr] and 32) = 0;πend;ππFunction JoystickExists : Boolean;πVar Regs : Registers;πbeginπ  JoystickExists := not ((JoystickPosX = 0) and (JoystickPosY = 0));πend;ππend.πππ{ππProgram JoyTest;ππUses Crt, Dos, AniVGA, Joystick;ππVar XMin, XMax, YMin, YMax,π   XRange, YRange,π   X, Y,π   PosX, PosY,π   Bullet1X, Bullet1Y,π   Bullet2X, Bullet2Y : Integer;π   Shooting1, Shooting2 : Boolean;π   ShootNext : Boolean;ππProcedure CalibrateJoystick (Var XMin, XMax, YMin, YMax : Integer);πbeginπ  Write ('Press joystick to upper left corner and press button one...');π  Repeat Until JoystickButtonA;π  XMin := JoystickPosX;π  YMin := JoystickPosY;π  Writeln ('OK.');π  Repeat Until not JoystickButtonA;π  Write ('Press joystick to lower right corner and press button two...');π  Repeat Until JoystickButtonB;π  XMax := JoystickPosX;π  YMax := JoystickPosY;π  Writeln ('OK.');π  Repeat Until not JoystickButtonB;πend;ππProcedure AnimateShip;πbeginπ  X := JoystickPosX - XMin;π  if (X <= XRange div 3) thenπ     Dec (PosX, 3)π  else if (X > XRange * 2 div 3) thenπ     Inc (PosX, 3);π  Y := JoystickPosY - YMin;π  if (Y <= YRange div 3) thenπ     Dec (PosY, 3)π  else if (Y > YRange * 2 div 3) thenπ     Inc (PosY, 3);π  SpriteX [0] := PosX;π  SpriteY [0] := PosY;πend;ππProcedure AnimateBullets;πbeginπ  if Shooting1 thenπ     if (Bullet1Y < 0) thenπ        Shooting1 := Falseπ     elseπ        Dec (Bullet1Y, 8)π  elseπ     beginπ        Bullet1X := PosX + 3;π        Bullet1Y := PosY + 14;π     end;π  if Shooting2 thenπ     if (Bullet2Y < 0) thenπ        Shooting2 := Falseπ     elseπ        Dec (Bullet2Y, 8)π  elseπ     beginπ        Bullet2X := PosX + 30;π        Bullet2Y := PosY + 14;π     end;π  SpriteX [1] := Bullet1X;π  SpriteY [1] := Bullet1Y;π  SpriteX [2] := Bullet2X;π  SpriteY [2] := Bullet2Y;πend;ππbeginπ  if JoystickExists and (LoadSprite ('SHIP1.COD', 1) = 1) andπ     (LoadSprite ('BULLET.COD', 2) = 1) thenπ     beginπ        ClrScr;π        CalibrateJoystick (XMin, XMax, YMin, YMax);π        ClrScr;π        InitGraph;π        SpriteN [0] := 1;π        SpriteN [1] := 2;π        SpriteN [2] := 2;π        PosX := 160;π        PosY := 160;π        Shooting1 := False;π        XRange := XMax - XMin;π        YRange := YMax - YMin;π        ShootNext := Boolean (0);π        While not (JoystickButtonA and JoystickButtonB) doπ           beginπ              if JoystickButtonA and not JoystickButtonB thenπ                 if not Shooting1 and ShootNext thenπ                    beginπ                       Bullet1X := PosX + 3;π                       Bullet1Y := PosY + 14;π                       Shooting1 := True;π                       ShootNext := False;π                    endπ                 else if not Shooting2 and not ShootNext thenπ                    beginπ                       Bullet2X := PosX + 30;π                       Bullet2Y := PosY + 14;π                       Shooting2 := True;π                       ShootNext := True;π                    end;π              While JoystickButtonA doπ                 beginπ                    AnimateShip;π                    AnimateBullets;π                    Animate;π                 end;π              AnimateShip;π              AnimateBullets;π              Animate;π           end;π        CloseRoutines;π     endπ  elseπ     Writeln ('Game card not installed.');πend.ππI apologize For giving you an example that Uses another Unit.  if need be, thisπProgram can be easily modified to provide a successful example.  Hope thisπhelps, and I hope my Programming is not toO bad.π}                                            6      05-31-9308:11ALL                      SWAG SUPPORT TEAM        Two Joysticks            IMPORT              95          ==============================================================================π BBS: «« The Information and Technology Exchanπ  To: MATT CRILL                   Date: 01-05─92 (23:03)πFrom: DANIEL CHURCHMAN           Number: 4144   [101] PASCALπSubj: JOYSTICK 1                 Status: Publicπ------------------------------------------------------------------------------πProgram Joy;  { Read Joystick positions and button states }ππUses DOS, Crt;ππConstπ  Buttons          : Byte = 0;π  Joystick         : Byte = 1;ππ  JoyIntr          : Byte = $15;π  JoyFunc          : Byte = $84;ππ  CStart           : Byte = 0; { To hold cursor start line }π  CEnd             : Byte = 0; { To hold cursor end line }ππ  kX               : Real = 6.25; { constant for horizontal conversion }π  kY               : Real = 20.0; { constant for vertical conversion }ππ  LastKey          : Char = ' ';ππVarπ  { Variables for Joystick 1 }π  Joy1Vert         : Word; { Vertical Position }π  Joy1Hori         : Word; { Horizontal Position }π  Joy1But1         : Boolean; { Button 1 }π  Joy1But2         : Boolean; { Button 2 }ππ  { Variables for Joystick 2 }π  Joy2Vert         : Word; { Vertical Position }π  Joy2Hori         : Word; { Horizontal Position }π  Joy2But1         : Boolean; { Button 1 }π  Joy2But2         : Boolean; { Button 2 }ππ  Error            : Boolean; { We'll set this if the joystick isn't found }ππ  Regs             : Registers;π  NewX, NewY       : Byte;π  OldX, OldY       : Byte;π  MinX, MinY,π  MaxX, MaxY       : Word;ππ{ Checkjoy and CheckBut are really the only two procedures of real }π{ interest to you; the rest is just support code to do something   }π{ with the samples.                                                }πππProcedure CheckJoy;π    begin   { Prepare and make Int 15h, subfunction 84h call }π      With Regs doπ      beginπ        AH := JoyFunc;π        DX := Joystick;  { Subfunction 1 = joystick }π        Intr(JoyIntr, Regs);π        Joy1Hori := AX;π        Joy1Vert := BX;π        Joy2Hori := CX;π        Joy2Vert := DX;π        Error := ((Flags AND FCarry) <> 0)π      end;π    end;ππProcedure CheckBut;π    Constπ      MaskJ1B1     = $10;π      MaskJ1B2     = $20;π      MaskJ2B1     = $40;π      MaskJ2B2     = $80;π    begin   { Prepare and make Int 15h, subfunction 84h call }π      With Regs doπ      beginπ        AH := JoyFunc;π        DX := Buttons;  { Subfunction 0 = buttons }π        Intr(JoyIntr, Regs);π        Joy1But1 := (AL AND MaskJ1B1) <> MaskJ1B1;π        Joy1But2 := (AL AND MaskJ1B2) <> MaskJ1B2;π        Joy2But1 := (AL AND MaskJ2B1) <> MaskJ2B1;π        Joy2But2 := (AL AND MaskJ2B2) <> MaskJ2B2;π        Error := ((Flags AND FCarry) <> 0)π      end;π    end;ππProcedure Calibrate;π    Varπ      n            : Byte;π    beginπ      { Calibrate joystick 1 }π      CheckJoy;π      If Error thenπ      beginπ        Write('No Joystick(s) found - terminating program');π        Halt(1)π      end;ππ      If (Joy1Vert + Joy1Hori) = 0 thenπ        Writeln('Joystick 1 Absent')π      elseπ        Writeln('Joystick 1 Present');π      If (Joy2Vert + Joy2Hori) = 0 thenπ        Writeln('Joystick 2 Absent')π      elseπ        Writeln('Joystick 2 Present');ππ(*      { Get centre joystick values for X and Y }π      Write('Hold joystick in centre position and press a button');π      Repeatπ        CheckButπ      Until (Joy1But1 OR Joy1But2);π      CentreX := 0;π      CentreY := 0;π      For n := 1 to 10 doπ      beginπ        CheckJoy;π        CentreX := CentreX + Joy1Hori;π        CentreY := CentreY + Joy1Vert;π      end;π      CentreX := CentreX DIV 10;π      CentreY := CentreY DIV 10;π      While (Joy1But1 OR Joy1But2) do  { Wait till button released }π      beginπ        CheckButπ      end;π      Writeln('  -  ',CentreX,':',CentreY);π*)ππ      { Get minimum joystick values for X and Y }π      Write('Hold joystick in upper-left position and press a button');π      Repeatπ        CheckButπ      Until (Joy1But1 OR Joy1But2);π      MinX := 0;π      MinY := 0;π      For n := 1 to 10 do  { Sample over time for accuracy }π      beginπ        CheckJoy;π        { Bias the reading slightly to ensure }π        { we can always reach coord 1,1 }π        MinX := MinX + Word(Round(Joy1Hori * 1.1));π        MinY := MinY + Word(Round(Joy1Vert * 1.1))π      end;π      MinX := MinX DIV 10;π      MinY := MinY DIV 10;π      While (Joy1But1 OR Joy1But2) do  { Wait till button released }π      beginπ        CheckButπ      end;π      Writeln('  -  ',MinX,':',MinY);ππ      { Get maximum joystick values for X and Y }π      Write('Hold joystick in bottom-right position and press a button');π      Repeatπ        CheckButπ      Until (Joy1But1 OR Joy1But2);π      MaxX := 0;π      MaxY := 0;π      For n := 1 to 10 do   { Sample over time for accuracy }π      beginπ        CheckJoy;π        { Bias the reading slightly to ensure }π        { we can always reach coord 80,25 }π        MaxX := MaxX + Word(Round(Joy1Hori * 0.95));π        MaxY := MaxY + Word(Round(Joy1Vert * 0.95))π      end;π      MaxX := MaxX DIV 10;π      MaxY := MaxY DIV 10;π      While (Joy1But1 OR Joy1But2) do  { Wait till button released }π      beginπ        CheckButπ      end;π      Writeln('  -  ',MaxX,':',MaxY);ππ      { Important to note that the following calculations of kX and   }π      { kY is done linearly.  This is not really correct, as you'll   }π      { see by the fact that when centred, your screen coords are     }π      { NOT 40,13.  The reason is that the resistors in joysticks     }π      { work on a logarithmic scale.  My knowledge of logs is too     }π      { rusty to build this in properly, so I've skipped it.  What    }π      { you should do is derive the log that correctly passes through }π      { minimum, maximum AND centre.  This way, the joystick, centred }π      { will correctly position your screen coord dead centre, and    }π      { you can still reach the extremes as well.                     }ππ      kX := (MaxX - MinX) / 80;π      kY := (MaxY - MinY) / 25;π      Writeln('kX = ', kX:0:2,'     kY = ',kY:0:2);ππ    end;ππ[Continued]πππ--- Msged/sqπ * Origin: C&O Systems, Brisbane, AUSTRALIA (3:640/777)π==============================================================================π BBS: «« The Information and Technology Exchanπ  To: MATT CRILL                   Date: 01-05─92 (23:04)πFrom: DANIEL CHURCHMAN           Number: 4145   [101] PASCALπSubj: JOYSTICK 2                 Status: Publicπ------------------------------------------------------------------------------πProcedure SetCoord;π    beginπ      If Joy1Hori < MinX then NewX := 1 elseπ        NewX := Byte(Round((Joy1Hori - MinX) / kX));π      If Joy1Vert < MinY then NewY := 1 elseπ        NewY := Byte(Round((Joy1Vert - MinY) / kY));ππ      If NewX = 0 then NewX := 1;π      If NewX > 80 then NewX := 80;π      If NewY = 0 then NewY := 1;π      If NewY > 25 then NewY := 25;ππ    end;ππProcedure MoveIndicator;π    beginππ      { If the position has changed, clean up old indicator }π      If NOT ((OldX = NewX) AND (OldY = NewY)) thenπ      beginππ        { Turn off indicator at old position }π        With Regs doπ        beginπ          { First, move cursor to old position }π          AH := 2;   { Set cursor position                }π          BH := 0;   { Assume page 0                      }π          DH := OldY - 1; { This value must be zero-based }π          DL := OldX - 1; { This one too                  }π          Intr($10,Regs);ππ          { Now change the attribute }π          AH := 8;   { Read what character is there now                  }π          BH := 0;   { I'm assuming page 0                               }π          Intr($10,Regs);  {AH now holds the attribute, AL the character }π          AH := 9;   { Write Character and Attribute, AL is ok, so...    }π          BL := 31;  { ...only change the attribute                      }π          BH := 0;   { Again, assume page 0                              }π          CX := 1;   { Number of characters to write                     }π          Intr($10,Regs)π        endπ      end;π      { Always refresh the current position }ππ      With Regs doπ      beginπ        { Next, move cursor to new position }π        AH := 2;   { Set cursor position                }π        BH := 0;   { Assume page 0                      }π        DH := NewY - 1; { This value must be zero-based }π        DL := NewX - 1; { This one too                  }π        Intr($10,Regs);ππ        { Then, turn on indicator at NEW position }π        AH := 8;   { Read what character is there now                  }π        BH := 0;   { I'm assuming page 0                               }π        Intr($10,Regs);  {AH now holds the attribute, AL the character }π        AH := 9;   { Write Character and Attribute, AL is ok, so...    }π        BL := 112; { ...change the attribute to black on grey          }π        BH := 0;   { Again, assume page 0                              }π        CX := 1;   { Number of characters to write                     }π        Intr($10,Regs)ππ      end;ππ    end;ππProcedure InitScreen;π    beginπ      GotoXY(26,10);π      Write('Joystick 1        Joystick 2');π      GotoXY(20,12);π      Write('X :');π      GotoXY(20,13);π      Write('Y :');π      GotoXY(14,14);π      Write('Buttons :');π      GotoXY(16,16);π      Write('Error =');π      GotoXY(20,23);π      Write('Press "C" to reCalibrate your joystick');ππ      With Regs doπ      begin      { First, save present cursor configuration }ππ        AH := 3; { Read cursor pos and config }π        BH := 0; { Assuming we are using page 0 }π        Intr($10,Regs);π        CStart := CH; { Starting line of cursor }π        CEnd   := CL; { Ending line of cursor }π        { DH holds cursor row }π        { DL holds cursor column }ππ        { Now turn the cursor off - we hope! }ππ        AH := 1;  { Set cursor type }π        CH := $20; { Should cause the cursor to disappear }π        Intr($10,Regs);ππ      endπ    end;ππProcedure GetKey;π    beginπ      If KeyPressed thenπ      beginπ        LastKey := ReadKey;  { Read the key in the buffer       }π        If LastKey = #0 then { The key is an extended character }π          LastKey := ReadKey { Read the extended value          }π      end elseπ        LastKey := #0π    end;ππ[Continued]ππ--- Msged/sqπ * Origin: C&O Systems, Brisbane, AUSTRALIA (3:640/777)π==============================================================================π BBS: «« The Information and Technology Exchanπ  To: MATT CRILL                   Date: 01-05─92 (23:05)πFrom: DANIEL CHURCHMAN           Number: 4146   [101] PASCALπSubj: JOYSTICK 3                 Status: Publicπ------------------------------------------------------------------------------πbeginπ  TextAttr := 31;  { White on Blue - my favourite :-) }π  ClrScr;ππ  Calibrate;π  SetCoord;ππ  InitScreen;ππ  Repeatπ    GetKey;  { Simply load the variable LastKey with }π             { a keystroke if one is available       }π    CheckJoy;π    CheckBut;π    OldX := NewX;π    OldY := NewY;π    SetCoord;π    GotoXY(24,12);π    Write(Joy1Hori:10);π    GotoXY(24,13);π    Write(Joy1Vert:10);π    GotoXY(31,14);π    Write((Joy1But1):5,':',(Joy1But2):5);ππ    GotoXY(44,12);π    Write(Joy2Hori:10);π    GotoXY(44,13);π    Write(Joy2Vert:10);π    GotoXY(51,14);π    Write(Byte(Joy2But1),':',Byte(Joy2But2));ππ    GotoXY(37,15);π    Write(NewX:2,':',NewY:2);ππ    GotoXY(24,16);π    Write(Error:5);ππ    Writeln;π    MoveIndicator;ππ    If UpCase(LastKey) = 'C' thenπ    beginπ      ClrScr;π      Calibrate;π      InitScreenπ    end;ππ  Until LastKey = #27;ππ  With Regs doπ  begin      { Restore original cursor configuration }ππ    AH := 1;  { Set cursor type }π    CH := CStart; { Original cursor start line }π    CL := CEnd;   { Original cursor end line }π    Intr($10,Regs);π    GotoXY(1,24)π  end;ππend.ππππ[End of code]π--- Msged/sqπ * Origin: C&O Systems, Brisbane, AUSTRALIA (3:640/777)π